package com.wakyde.config;

import io.swagger.annotations.ApiModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
public class SwaggerConfig {

    @Bean
    public Docket docket(Environment environment){
        // 决定要显示的环境
        Profiles profiles = Profiles.of("dev","test");
        // 判断是否属于当前的环境
        boolean flag = environment.acceptsProfiles(profiles);
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("AAA")
                .enable(flag) // 关闭或开启swagger
                .select()
                //RequestHandlerSelectors 配置扫描接口的方式
                // any() 扫描全部
                // none() 不扫描
                //basePackage() 指定扫描的包
                //withClassAnnotation() 扫描类上的注解
                //withMethodAnnotation() 扫描方法上的注解
                .apis(RequestHandlerSelectors.any())
                // paths() 过滤路径
                .paths(PathSelectors.ant("/**"))
                .build();
    }

    @Bean
    public Docket docket1(Environment environment){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("BBB")
                .select()
                .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.ant("/**"))
                .build();
    }

    @Bean
    public ApiInfo apiInfo(){
        // 作者的信息
        Contact contact = new Contact("wakyde", "http://www.baidu.com", "wakydeddd@163.com");
        return new ApiInfo("凌大侠的SwaggerApi文档",
                "敷设电缆所得税率",
                "v1.0",
                "https://www.baidu.com",
                contact,
                "Apache 2.0",
                "http:www.apche.org/licenses/LICENSE-2.0",
                new ArrayList<>());
    }
}
